﻿using System.Linq;
using System.Web.Mvc;
using ASPItalia.ModelVirtualCasting.Web.Filters;
using ASPItalia.ModelVirtualCasting.Web.Models;
using ASPItalia.ModelVirtualCasting.Common;

namespace ASPItalia.ModelVirtualCasting.Web.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
		public ActionResult Index()
		{
			IModelRepository models = ApplicationContext.Current.Models;
			var modelleDaMostrare = models.GetRandomModels(5);

			HomepageViewModel viewModel = new HomepageViewModel();
			viewModel.Models.AddRange(modelleDaMostrare);

			INewsRepository news = ApplicationContext.Current.News;
			viewModel.News.AddRange(news.GetLastNews(5));

			return View(viewModel);

		}


        #region Better Index
		//[ShowNews(Number = 5)]
		//[ShowModels(Number = 5)]
		//public ActionResult Index()
		//{
		//    this.ViewData.Model = new HomepageViewModel();
		//    return View();
		//}
        #endregion

        #region News action
        public ActionResult News(int id)
        {
            INewsRepository repository =
                ApplicationContext.Current.News;

            this.ViewData.Model = new NewsViewModel
            {
                News = repository.GetByID(id)
            };

            return View();
        }
        #endregion
    }
}